--[[
	BG Twink Auto XP Off  (Huge thanks to jiminizer for the code!)
]]

local timer = 0.4 -- Change value depending on how long of a delay you need in seconds (1.0 = 1 second; default = 0.9)

local f = CreateFrame("Frame");
f:Hide();
f:SetScript("OnUpdate",function(self,elapsed)
	f.delay = f.delay - elapsed;
	if f.delay <= 0 then
		_G[f.popup.."Button1"]:Click();
		f:Hide();
	end
end);

hooksecurefunc(StaticPopupDialogs["CONFIRM_BATTLEFIELD_ENTRY"],"OnAccept",function(self,data)
	f.popup = StaticPopup_Visible("GOSSIP_CONFIRM");
	if f.popup then
		local _,_,home,world = GetNetStats();
		local fps = GetFramerate();
		f.delay = timer-(1/fps); 
		f:Show();
	end
end);

SlashCmdList["BGTWINK"] = function(msg)
	msg = msg and tonumber(msg)
	if msg then
		timer = msg;
		DEFAULT_CHAT_FRAME:AddMessage("\124cFFF00000\Timer set to: "..msg);
	else
		DEFAULT_CHAT_FRAME:AddMessage("\124cFFF00000\Invalid input. Use this command in the format: /bgt number");
	end
end
SLASH_BGTWINK1 = "/bgt";
SLASH_BGTWINK2 = "/bgtwink";